package com.itheima.server.controller;

import com.itheima.domain.UserInfo;
import com.itheima.server.service.MessagesService;
import com.itheima.vo.PageResult;
import com.itheima.vo.UserInfoVo;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Resource
    private MessagesService messagesService;


    /**
     * 环信id查询用户信息
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity<UserInfoVo> userInfo(String huanxinId){
        UserInfoVo userInfoVo = messagesService.getUserInfo(huanxinId);
        return ResponseEntity.ok(userInfoVo);
    }


    /**
     * 联系人添加
     * @param map
     * @return
     */
    @PostMapping("/contacts")
    public ResponseEntity<String> contacts(@RequestBody Map map){
        long userId = Long.parseLong(map.get("userId").toString());
        messagesService.contacts(userId);
        return ResponseEntity.ok("OK");
    }

    /**
     * 查询好友列表
     * @param keyword
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/contacts")
    public ResponseEntity<PageResult> contactsList(String keyword,@RequestParam(defaultValue = "1") Integer page,
                                                   @RequestParam(defaultValue = "10") Integer pagesize){
        PageResult pageResult = messagesService.friendList(keyword,page,pagesize);
        return ResponseEntity.ok(pageResult);
    }


}
